using System;
using Spring.Data.NHibernate.Support;
using Spring.Data.NHibernate;
using NHibernate; 
using NHibernate.Criterion;
using System.Collections.Generic;
using System.Collections;
namespace pos.entity
{
    /// <summary>
    /// Summary description for 当日销售流水 数据库访问类
    /// </summary>
    public partial  class SaleDao:Dao<Sale>
    {

        public struct TSale
        {
            public string id;
            public  double amount;
            public double money;
        }
        public TSale GetSaleInfo(string id)
		 {
             dc = DC.Add(Restrictions.Eq("commodityID",id));
             ProjectionList pl = Projections.ProjectionList()
               .Add(Projections.SqlProjection("sum(saleAmount) as b", new String[] { "b" }, new NHibernate.Type.IType[] { NHibernate.NHibernateUtil.Double }))
               .Add(Projections.SqlProjection("sum(saleAmount*salePrice) as a", new String[] { "a" }, new NHibernate.Type.IType[] { NHibernate.NHibernateUtil.Double }));


             Object[] rs = (Object[])this.uniqueResult(dc.SetProjection(pl));
            TSale t=new TSale();
            if (rs == null)
            {
                t.id = id;
                t.amount = 0;
                t.money = 0;
            }
            else
            {
                t.amount = Convert.ToDouble(rs[0]);
                t.money = Convert.ToDouble(rs[1]);
            }
            

             return t;
		 }

      
       
    }
}

